Oxford Cambridge and RSA
GCSE (9-1) Computer Science
Algorithms & Programming
J277/02
Topic: 2.2 Programming Fundamentals (Sub-programs)
Time allowed: 40 minutes
Centre number Candidate number
First name Last name
INSTRUCTIONS INFORMATION
Turn over
Section A: Core Concepts & Scope
1
Fill in the missing keywords using OCR Exam Reference Language or Python to complete the function definition.
......................... calculate_area(width, height) area = width * height ......................... area endfunction result = calculate_area(5, 10) print(result)
[2]
2
Explain the difference between a Function and a Procedure.
[2]
3
The following code uses Global and Local variables.
score = 10 # Global variable def update_score(): score = 50 # Local variable print(score) update_score() print(score)
State the output of this program.
[2]
Section B: Debugging & Logic
4
A programmer has written a function check_password that takes a user_input string as a parameter and returns True if it matches "SeCrEt".

However, the function contains a Logic Error that makes the parameter useless.
01 function check_password(user_input) 02 user_input = input("Enter password: ") 03 if user_input == "SeCrEt" then 04 return True 05 else 06 return False 07 endif 08 endfunction
(a) Identify the line number causing the logic error.
[1]
Line:

(b) Explain why this line causes an error in the logic of using a sub-program.
[2]
Turn over
5
Trace the execution of this algorithm.
def math_trick(a, b): c = a + b if c > 10: return c - 2 else: return c * 2 val1 = 5 val2 = 3 result = math_trick(val1, val2) print(result)
[3]
a b c c > 10 Returned Value Output
Section C: Coding & Application
6
Create a Function named get_discount.
The function must:
  • Accept one parameter: price (Real/Float).
  • Check if the price is greater than 100.
  • If it is, calculate a new price with 10% off (multiply by 0.9).
  • If it is not, keep the price the same.
  • Return the final price.
Critical: Do not ask for user input inside the function.
[6]
7
A student has written a program that calculates the area of a circle in three different places in their code by copying and pasting the formula 3.142 * r * r every time.

(a) Refine this approach by suggesting a better programming technique.
[1]

(b) Explain two benefits of your suggested technique for the programmer.
[4]
8
In the code line result = calculate_area(5, 10), are the values 5 and 10 called Parameters or Arguments?
[1]
END OF QUESTION PAPER